﻿Imports System
Imports System.IO
Imports System.Runtime.Serialization
Imports System.Runtime.Serialization.Formatters.Binary
<Serializable()> Public Class GroupsCollection
    Inherits System.Collections.CollectionBase
    Implements ICloneable
    Private m_nSeiral As Integer = 0
    ''' <summary>
    ''' 污染源分组中的序号
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Property nSeiral() As Integer
        Get
            Return Me.m_nSeiral
        End Get
        Set(ByVal value As Integer)
            Me.m_nSeiral = value
        End Set
    End Property
    ''' <summary>
    ''' 添加集合
    ''' </summary>
    ''' <param name="Group"></param>
    ''' <remarks></remarks>
    Public Sub Add(ByVal Group As Group)
        '初始化参数
        nSeiral += 1
        Group.GroupID = "Group" & nSeiral
        Group.Name = "分组" & nSeiral
        List.Add(Group)
    End Sub
    ''' <summary>
    ''' 删除集合
    ''' </summary>
    ''' <param name="index"></param>
    ''' <remarks></remarks>
    Public Sub Remove(ByVal index As Integer)
        ' Check to see if there is a widget at the supplied index.
        If index > Count - 1 Or index < 0 Then
            ' If no widget exists, a messagebox is shown and the operation is 
            ' cancelled.
            System.Windows.Forms.MessageBox.Show("Index not valid!")
        Else
            ' Invokes the RemoveAt method of the List object.
            List.RemoveAt(index)
        End If
    End Sub

    Public Property Item(ByVal index As Integer) As Group
        Get
            Return CType(List.Item(index), Group)
        End Get
        Set(ByVal value As Group)
            List.Item(index) = value
        End Set
    End Property
    ''' <summary>
    ''' 根据污染物重新设置所有分组中的污染源数据
    ''' </summary>
    ''' <param name="AllSource"></param>
    ''' <remarks></remarks>
    Public Sub ResetGroupSource(ByVal AllSource As Source)
        For i As Integer = 0 To Me.Count - 1
            Me.Item(i).ResetSource(AllSource)
        Next
    End Sub
    ''' <summary>
    ''' 返回ProjSetCollection对象的副本
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Clone() As Object Implements System.ICloneable.Clone
        Dim objCopy As New GroupsCollection
        objCopy.m_nSeiral = Me.m_nSeiral
        For i As Integer = 0 To Me.List.Count - 1
            objCopy.List.Add(CType(Me.List.Item(i), Group).Clone)
        Next
        Return objCopy
    End Function
End Class
